package work.lrl.thirdCodeMapping;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import core.util.TransformCsvData;
import lombok.Builder;
import lombok.Data;

import java.util.*;

public class Demo {
    private final static String base = "C:\\Users\\Gong.Yang\\Desktop\\lrl\\mapping\\";
    private final static String source = base + "source.csv";
    private final static String allData = base + "allData.csv";
    private final static String result = base + "result.xlsx";

    public static void main(String[] args) {
        Set<String> sourceSet = new HashSet<>();
        TransformCsvData.peekCsv(source, 0, x -> sourceSet.add(x[0]));

        List<ExcelObject> list = new ArrayList<>();
        TransformCsvData.peekCsv(allData,0,x->{
            if (x.length<2){
                return;
            }
            if (!sourceSet.contains(x[1])){
                return;
            }
            list.add(ExcelObject.builder().thirdCode(x[1]).unionId(x[0]).build());
        });

        EasyExcel.write(result).sheet().doWrite(list);

    }

    @Data
    @Builder
    @ColumnWidth(value = 20)
    public static class ExcelObject {
        @ExcelProperty("三方卡号")
        private String thirdCode;

        @ExcelProperty("unionId")
        private String unionId;
    }
}
